package iscript.gameFramework.IsoLibarys.display 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import iscript.coreFramework.displays.Element;
	import iscript.gameFramework.IsoLibarys.state.IsoTileState;
	import iscript.gameFramework.IsoLibarys.util.IsoUtil;


	
	/**
	 * 单个平铺对象
	 */
	public class IsoTile extends IsoObject
	{
		//private  var _bitmapReader:Bitmap;
		private  var _bitmapReader:Shape;
		private  var _textCoord:TextField = new TextField();
		private  var _state:String;
		
		public function IsoTile(row:int,column:int,rectangle:Rectangle)  
		{
			super(row, column, rectangle);
			//_bitmapReader = new Bitmap( IsoBitmapData.normal());
			_bitmapReader = new Shape();
			addChild(_bitmapReader);
			_textCoord.text = row + "," + column;
			_textCoord.selectable = false;
			_textCoord.mouseEnabled = false;
			_textCoord.autoSize = TextFieldAutoSize.LEFT;
			_textCoord.x =  bound.width / 2 - _textCoord.width/2
			_textCoord.y =  bound.height / 2 - _textCoord.height/2;
			addChild(_textCoord);
			addEventListener(Event.ADDED_TO_STAGE, _addToStageLogic);	
		    setState(IsoTileState.NORMAL)
		}
		
		private function _addToStageLogic(e:Event):void{
			removeEventListener(Event.ADDED_TO_STAGE, _addToStageLogic);
		}
		
		public function setState (data:String):void {
			   _state = data;
			   switch(_state) {
				   case IsoTileState.NORMAL:
					   normal();
					   break;
				   case IsoTileState.HOVER:
					   hover();
					   break;
				   }
			}
		public function getState ():String { return _state; }
		
		private function normal():void { 
			//_bitmapReader.bitmapData = IsoBitmapData.normal()
			IsoBitmapData.normalShape(_bitmapReader)
			}
		
		private function hover():void { 
			//_bitmapReader.bitmapData = IsoBitmapData.hover();
			IsoBitmapData.hoverShape(_bitmapReader)
			}
		

		public function  set textCoordVisible(value:Boolean):void {
			   _textCoord.visible = value;
			}
		public function  get textCoordVisible():Boolean { return _textCoord.visible; }
		
	}

}